package guestbook;

import java.io.IOException;
import java.util.Date;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SignMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost( HttpServletRequest req, HttpServletResponse resp )
			throws ServletException, IOException {
		String username = req.getParameter( "username" );
		String usermessage = req.getParameter( "usermessage" );
		Date messageDate = new Date();
		
		Message msg = new Message( username, usermessage, messageDate );
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent( msg );
		} finally {
			pm.close();
		}
		
		resp.sendRedirect( "/faltam.jsp" );
	}
	
}